package yxy.game.pm2.active.module.time;

import yxy.apple.util.redisson.RedisException;
import yxy.game.pm2.bean.module.BaseGameRedisBean;

public class TimeChallengeGroup extends BaseGameRedisBean {

	//bean -------------------------------------------------
	private int groups;	//

	public int getGroups() {
		return groups;
	}
	public void setGroups(int groups) {
		this.groups = groups;
	}

	//func --------------------------------------------------
	private static final int group = 7;	//

	public static int ChallengeGroup() {
		TimeChallengeGroup info = get();
		if(info == null) {
			return group;
		}
		return info.getGroups();
	}
	
	private static TimeChallengeGroup create() {
		TimeChallengeGroup lockinfo = new TimeChallengeGroup();
		lockinfo.setGroups(group);
		lockinfo.set();
		return lockinfo;
	}
	
	public void update() {
			
	}
	
	//redis --------------------------------------------------

	static private String key() {
		return "CHALLENGE:INFO";
	}

	public void set() {
		try {
			setv(key(), this);
		} catch (RedisException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 获取 
	 * @return
	 */
	static public TimeChallengeGroup get() {
		try {

			TimeChallengeGroup module = getv(key());
			if (module == null) {
				module = create();
			}

			return module;
		} catch (RedisException e) {
			e.printStackTrace();
		}
		return null;
	}

	// lock==========================================================================

	@Override
	public String lockKey() {
		return String.format("lock:%s", key());
	}
	
}